﻿package net.wangit.jdbc.generator;

import net.wangit.util.Checker;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class IncrementorFactory {

	private static Log log = LogFactory.getLog(IncrementorFactory.class);

	public IncrementorFactory() {
	}

	public static synchronized Incrementor getIncrementor(String domain,
			String id) {
		if (Checker.isEmpty(domain) || Checker.isEmpty(id)) {
			log.error((new StringBuilder(
					"empty arguments is not acceptable: domain="))
					.append(domain).append(" id=").append(id).toString());
			return null;
		}
		id = id.toLowerCase();
		Incrementor i = IncrementorCache.get(domain, id);
		if (i == null) {
			i = new Incrementor(domain, id);
			IncrementorCache.put(domain, id, i);
		}
		return i;
	}

}
